package com.javabasic.algorithm.sword_of_offer;

/**
 * @author mir.xiong
 * @version 1.0
 * @description
 * @see
 * @since Created by work on 2022/1/13 11:38 下午
 */
public class 剑指_Offer_63_股票的最大利润 {

    /**
     * 动态规划
     * @param prices
     * @return
     */
    public int maxProfit(int[] prices) {
        int len = prices.length;
        if (len == 0) {
            return 0;
        }
        int MIN_VALUE = prices[0], result = 0;
        for (int i = 1; i < len; i++) {
            if (prices[i] - MIN_VALUE > result) {
                result = prices[i] - MIN_VALUE;
            }
            if (prices[i] < MIN_VALUE) {
                MIN_VALUE = prices[i];
            }
        }
        return result;
    }
}
